SimpleApp.java

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class SimpleApp extends MIDlet implements CommandListener {
    
    private Display _display;
    private Form _screen;
    private List _menu;
    private TextBox _about;
    
    private Command _aboutExitCommand;
    private Command _screenExitCommand;
    private Command _choiceCommand;
    
    private final String[] _elements={"Start","About","Exit"};
    private Image _image;
    
    public SimpleApp(){
        
        _display = Display.getDisplay(this);
        _menu=new List("Menu",List.IMPLICIT,_elements,null);
        _about=new TextBox("About","Simple J2ME application written by Adam Witkowski and Lukasz Wojtus",100,TextField.ANY);
        _screen=new Form("Image");
        
        _choiceCommand = new Command("Choose", Command.SCREEN, 2);
        _aboutExitCommand=new Command("Back", Command.SCREEN, 2);
        _screenExitCommand=new Command("Back",Command.SCREEN, 2);
        
        _menu.addCommand(_choiceCommand);
        _menu.setCommandListener(this);
        _about.addCommand(_aboutExitCommand);
        _about.setCommandListener(this);
        _screen.addCommand(_screenExitCommand);
        _screen.setCommandListener(this);
        
        try {
            _image = Image.createImage(this.getClass().getResourceAsStream("pamela.png"));
        } catch (IOException e) {_menu.setTitle("dupa");}
        
        _screen.append(_image);
    }
   
    public void startApp(){
        _display.setCurrent(_menu);
    }
    
    public void pauseApp(){}
    
    public void destroyApp(boolean unconditional){}
    
    public void commandAction(Command c, Displayable s) {
        if (c == _choiceCommand) {
            
            switch(_menu.getSelectedIndex()) {
                case 0: {
                    _display.setCurrent(_screen);
                    break;}
                case 1: {
                    _display.setCurrent(_about);
                    break;}
                case 2: {
                    destroyApp(false);
                    notifyDestroyed();
                    break;
                }
            }
        }
        
        if (c == _aboutExitCommand) {
            _display.setCurrent(_menu);
        }
        
        if (c == _screenExitCommand) {
            _display.setCurrent(_menu);
        }
    }
}